import store from '../store/index.js'
import httpConfig from '@/config/httpConfig.js'
import {req} from "./requrest-base.js"; //文件路径请换成本地路径
req.defaultData.baseUrl = "http://api-uas.test.ptevent.cn"; //公共请求基础地址
// req.defaultData.baseUrl = "http://api-uas.putao.com";

req.defaultData.header.appkey =  httpConfig.server.appkey
let token = store.state.userinfo.token
req.defaultData.header.Authorization = token ? `Bearer ${token}` : '',




// req.defaultData.dataPublic.token = "0000-1111-2222-3333" //设置token值
req.defaultData.isRemoveNull = true; //是否处理后端传入数据为null的情况
//全局请求前置拦截

req.defaultData.beforeAjax = (data,task)=>{
    // task.abort(); //结束请求
}
//全局请求后置拦截 -> 后置拦截必须要设置,不然没有返回值
req.defaultData.afterAjax = (data)=>{
    return data;
}
//全局错误拦截
req.defaultData.error = (err,reject)=>{
    console.log(err); //错误信息
    //调用reject函数则Promise请求结束,并且程序报错，请看错误信息酌情使用
    reject(); //报错  
}
// Vue.prototype.$request = {req}; //挂载在原形上
export default req